#!/usr/bin/env bash

# Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

srcdir=tinyxml
cd ${srcdir} || exit 1

cxxflags="${CXXFLAGS} -DTINYXML_USE_STL"

for i in tinyxml tinyxmlparser tinyxmlerror tinystr; do
    ${CXX} ${cxxflags} -O3 -c ${i}.cpp -o ${i}.o
done
${AR} rcs libtinyxml.a tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o
rm tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o

for i in tinyxml tinyxmlparser tinyxmlerror tinystr; do
    ${CXX} ${cxxflags} -fPIC -O3 -c ${i}.cpp -o ${i}.o
done
${AR} rcs libtinyxml.a tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o
${LD} ${LDFLAGS} -shared -o libtinyxml.so.2.6.2 tinyxml.o tinyxmlparser.o tinyxmlerror.o tinystr.o
ln -sf libtinyxml.so.2.6.2 libtinyxml.so.2
ln -sf libtinyxml.so.2 libtinyxml.so
